package com.webermagem.model;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name="TB_SINTOMAS")
public class Sintoma {
	
	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)  
    @Column(name = "id", nullable = false, unique = true) 
	private long id;
	
	@ManyToOne
	@JoinColumn(name = "id_perfil")
	private TipoSintoma tipoSintoma;
	private String descricao;
	
	
	@ManyToMany(cascade=CascadeType.ALL)
	@JoinTable(name = "TB_SINT_DIAG", joinColumns = {@JoinColumn(name="id_sintoma") },	inverseJoinColumns = {@JoinColumn(name="id_diagnostico")}	)
	private Set<Diagnostico> diagnosticos;
	
	
	public long getId() {
		return id;
	}
	public void setId(long id) {
		this.id = id;
	}
	public TipoSintoma getTipoSintoma() {
		return tipoSintoma;
	}
	public void setTipoSintoma(TipoSintoma tipoSintoma) {
		this.tipoSintoma = tipoSintoma;
	}
	public String getDescricao() {
		return descricao;
	}
	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}
	public Set<Diagnostico> getDiagnosticos() {
		return diagnosticos;
	}
	public void setDiagnosticos(Set<Diagnostico> diagnosticos) {
		this.diagnosticos = diagnosticos;
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((descricao == null) ? 0 : descricao.hashCode());
		result = prime * result + (int) (id ^ (id >>> 32));
		result = prime * result
				+ ((tipoSintoma == null) ? 0 : tipoSintoma.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Sintoma other = (Sintoma) obj;
		if (descricao == null) {
			if (other.descricao != null)
				return false;
		} else if (!descricao.equals(other.descricao))
			return false;
		if (id != other.id)
			return false;
		if (tipoSintoma == null) {
			if (other.tipoSintoma != null)
				return false;
		} else if (!tipoSintoma.equals(other.tipoSintoma))
			return false;
		return true;
	}

}
